﻿using Newtonsoft.Json;
using System;
using System.Data;
using System.Web;
using Easy.Common;
using Easy.BLL;
using Easy.Operation;

namespace Easy.Web.Service.Data
{
    /// <summary>
    /// SoftOpeateN2NItem 的摘要说明
    /// </summary>
    public class SoftOpeateN2NItem : BaseHttpHandler
    {

        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string ids = context.Request["ids"];
            string entityA = context.Request["entityAname"];
            string entityM = context.Request["entityMname"];
            string entityB = context.Request["entityBname"];
            string linkentityid = context.Request["linkentityid"];
            string type = context.Request["type"];

            CustomResult cusResult = new CustomResult();
            try
            {
                //CURD curd = new CURD(entityName, this.CurrentUser);
                DataService service = new DataService(entityB, this.CurrentUserId);
                DataSet ds= service.N2NOpeate(ids, entityM, entityB,entityA,linkentityid, type);
                if(ds!=null)
                {
                    if(ds.Tables[0].Rows[0][0].ToString()=="0")
                    {
                        cusResult.ResultCode = 0;
                        cusResult.ResultMessage = "成功";
                    }
                    else
                    {
                        cusResult.ResultCode = -1;
                        cusResult.ResultMessage = ds.Tables[0].Rows[0][1].ToString();
                    }
                }
                
            }
            catch (CustomException ce)
            {
                cusResult = ce.CustomResult;
            }
            catch (Exception e)
            {
                cusResult.ResultCode = -1;
                cusResult.ResultMessage = e.Message;
            }
            finally
            {
                context.Response.Write(JsonConvert.SerializeObject(cusResult));
            }
        }

        
    }
}